2 Ensayando una implementación un poco diferente.
3 Encuentra el flujo máximo pero no permite reconstruir
4 la red de flujos, i.e, no sé cuanto material fluye de
18 int cap
[MAXN
+1][MAXN
+1], prev
[MAXN
+1];
20 int fordFulkerson(int n
, int s
, int t
){
23 fill(prev
, prev
+n
, -1);
26 while (q
.size() && prev
[t
] == -1){
29 for (int v
= 0; v
<n
; ++v
)
30 if (v
!= s
&& prev
[v
] == -1 && cap
[u
][v
] > 0)
31 prev
[v
] = u
, q
.push(v
);
34 if (prev
[t
] == -1) break;
36 int bottleneck
= INT_MAX
;
37 for (int v
= t
, u
= prev
[v
]; u
!= -1; v
= u
, u
= prev
[v
]){
38 bottleneck
= min(bottleneck
, cap
[u
][v
]);
40 for (int v
= t
, u
= prev
[v
]; u
!= -1; v
= u
, u
= prev
[v
]){
41 cap
[u
][v
] -= bottleneck
;
42 cap
[v
][u
] += bottleneck
;
51 while (scanf("%d", &n
) == 1 && n
){
52 for (int i
=0; i
<n
; ++i
){
53 fill(cap
[i
], cap
[i
]+n
, 0);
56 scanf("%d %d %d", &s
, &t
, &C
);
60 scanf("%d %d %d", &i
, &j
, &k
);
61 cap
[--i
][--j
] += k
, cap
[j
][i
] += k
;
64 printf("Network %d\nThe bandwidth is %d.\n\n", runs
++, fordFulkerson(n
, s
, t
));